package cc.zstart.utils;

import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class ListUtil {
	
	@SuppressWarnings("unchecked")
	public static <T> List<T> list(Class<T> cls, T... items){
		List<T> result = new ArrayList<T>();
		CollectionUtils.addAll(result, items);
		return result;
	}
	
	public static List<String> listStr(String... items) {
		return list(String.class, items);
	}
	
	public static List<Integer> listInt(Integer... items) {
		return list(Integer.class, items);
	}
	
	public static List<Long> listLong(Long... items) {
		return list(Long.class, items);
	}
	
	public static List<Float> listFloat(Float... items) {
		return list(Float.class, items);
	}
	
	public static List<Double> listDouble(Double... items) {
		return list(Double.class, items);
	}

	public static <T> List<T> listCase(Class<T> t, Object... items) {
		List<T> list = new ArrayList<T>();
		for (Object o : items) {
			list.add(BeanUtil.typeCast(t, o));
		}
		return list;
	}
	
	public static List<String> listCaseStr(Object... items) {
		return listCase(String.class, items);
	}
	
	public static List<Integer> listCaseInt(Object... items) {
		return listCase(Integer.class, items);
	}
	
	public static List<Long> listCaseLong(Object... items) {
		return listCase(Long.class, items);
	}
	
	public static <T> List<T> listCaseList(Class<T> t, List<?> list) {
		List<T> result = new ArrayList<T>();
		for (Object o : list) {
			result.add(BeanUtil.typeCast(t, o));
		}
		return result;
	}

	/**
	 * @Author DaiJG
	 * @Date 2018/1/17 13:57
	 * @Description string list 是否包含 str
	 * @param list
	 * @param str
	 * @param ignoreCase 忽略大小写
	 * @return
	 */
	public static boolean strContain(List<String> list, String str, boolean ignoreCase) {
		if (list == null) {
			return false;
		}
		if (str == null) {
			for (String one : list) if (one == null) return true;
		} else if (ignoreCase) {
			for (String one : list) if (str.equalsIgnoreCase(one)) return true;
		} else {
			for (String one : list) if (str.equals(one)) return true;
		}
		return false;
	}
}
